// Main entry point for the backend application
require('dotenv').config();
const app = require('./server');

const PORT = process.env.PORT || 3001;

app.listen(PORT, () => {
  console.log(`
🚀 God Token Staking System Backend Server is running!
📍 Port: ${PORT}
🌍 Environment: ${process.env.NODE_ENV || 'development'}
🕐 Started at: ${new Date().toLocaleString()}
📚 API Documentation: http://localhost:${PORT}/api/health
  `);

  // Initialize cron jobs for interest distribution
  const { distributeDailyInterest, sendUnclaimedInterestToHole } = require('./routes/staking');

  console.log(`
⏰ Scheduled Tasks:
  - Daily Interest Distribution: 2:00 PM UTC
  - Unclaimed Interest Processing: Every hour
  `);
});

// Graceful shutdown
process.on('SIGTERM', () => {
  console.log('SIGTERM received, shutting down gracefully');
  process.exit(0);
});

process.on('SIGINT', () => {
  console.log('SIGINT received, shutting down gracefully');
  process.exit(0);
});